import Mock from 'mockjs';

Mock.mock('/api/login', 'post', (options) => {
  const {
    username,
    password
  } = JSON.parse(options.body);

  if (username === 'admin' && password === '123456') {
    return {
      code: 200,
      message: '登录成功',
      token: 'fake-token',
    };
  } else {
    return {
      code: 401,
      message: '用户名或密码错误',
    };
  }
});

Mock.mock('/api/genders', 'get', () => {
  return [{
      value: '男',
      text: '男'
    },
    {
      value: '女',
      text: '女'
    },
  ];
});

Mock.mock('/api/grades', 'get', () => {
  return [{
      value: 'grade1',
      text: '一年级'
    },
    {
      value: 'grade2',
      text: '二年级'
    },
    {
      value: 'grade3',
      text: '三年级'
    },
    {
      value: 'grade4',
      text: '四年级'
    },
    {
      value: 'grade5',
      text: '五年级'
    },
    {
      value: 'grade6',
      text: '六年级'
    },
  ];
});

//旧的模拟数据
// Mock.mock('/api/users', 'get', () => {
//   return Mock.mock({
//     'users|20': [{
//       'id|+1': 1,
//       'username': '@cname',
//       'gender|1': ['男', '女'],
//       'grade|1': ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级'],
//       'phone': /^1[385][1-9]\d{8}$/,
//       'email': '@email',
//     }, ],
//   }).users;
// });

//新的模拟数据
Mock.mock('/api/users', 'get', () => {
  return Mock.mock({
    'users|20': [{
      'id|+1': 1,
      'firstName': '@first',
      'lastName': '@last',
      'password': '@string(8, 16)',
      'mobile': /^1[385][1-9]\d{8}$/,
      'email': '@email',
      'role|1': ['GCB Member', 'GBC Owner', 'Share Leaders', 'Marketing', 'Bank', 'Inversment Suite', 'Interns', 'Inv Industrial', 'Inv Commercial', 'Inv Profitability'],
      'isAdmin|1': [true, false],
      'company': '@company',
      'preferredBusinessName': '@word',
      'photo': '@image',
    }]
  }).users;
});